package com.mkh.st.common.utils.threadpool;

import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

import java.util.concurrent.*;

/**
 * 线程池自定义配置类，可自行根据业务场景修改配置参数。
 *
 * @Author yhj
 * @Date 2020/6/24
 **/
@Setter
@Getter

@ToString
public class CustomThreadPoolConfig {
	/**
	 * 线程池默认参数
	 */
//    private static final int DEFAULT_CORE_POOL_SIZE = Runtime.getRuntime().availableProcessors();
//    private static final int DEFAULT_MAXIMUM_POOL_SIZE_SIZE = Runtime.getRuntime().availableProcessors()*2;
	private static final int DEFAULT_CORE_POOL_SIZE = 4;
	private static final int DEFAULT_MAXIMUM_POOL_SIZE_SIZE = 8;
	private static final int DEFAULT_KEEP_ALIVE_TIME = 1;
	private static final TimeUnit DEFAULT_TIME_UNIT = TimeUnit.MINUTES;
	private static final int DEFAULT_BLOCKING_QUEUE_CAPACITY = 100;
	private static final RejectedExecutionHandler DEFAULT_HANDLER = new LogRejectedPolicy();
	/**
	 * 可配置参数
	 */
	private int corePoolSize = DEFAULT_CORE_POOL_SIZE;
	private int maximumPoolSize = DEFAULT_MAXIMUM_POOL_SIZE_SIZE;
	private long keepAliveTime = DEFAULT_KEEP_ALIVE_TIME;
	private TimeUnit unit = DEFAULT_TIME_UNIT;
	private int blockingQueueCapacity = DEFAULT_BLOCKING_QUEUE_CAPACITY;
	private RejectedExecutionHandler defaultHandler = DEFAULT_HANDLER;
	/**
	 * 使用有界队列
	 */
	private BlockingQueue<Runnable> workQueue = new ArrayBlockingQueue<>(blockingQueueCapacity);
}
